package com.zrrd.straw1.controller;


import com.zrrd.straw1.entity.User;
import com.zrrd.straw1.service.IUserService;
import com.zrrd.straw1.vo.Result;
import com.zrrd.straw1.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    IUserService userService;

    //需要什么，就在参数列表声明，SpringMVC负责提供。
    @GetMapping("/me")
    public Result<UserVo> me( @AuthenticationPrincipal UserDetails userDetails){
        UserVo userVo = userService.getCurrentUserVo( userDetails.getUsername() ) ;
        return Result.ok(userVo);
    }

    //对外开放一个访问的接口
    @GetMapping("/teachers")
    public Result<List<User>> master(){
        List<User> list = userService.getMaster();
        return Result.ok(list);
    }

}
